package com.example.administrator.yuejian23.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian23.Bean.ConInfo;
import com.example.administrator.yuejian23.Const;
import com.example.administrator.yuejian23.Fragment.viewholder.ContestListViewHolder;
import com.example.administrator.yuejian23.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/11/1.
 */

public class ContestListAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<ConInfo> contestLists;
    private  View view;
    public ContestListAdapter(Context c,List<ConInfo> list)
    {
        this.context=c;
        this.contestLists=list;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view=LayoutInflater.from(context).inflate(R.layout.item_contest_list,viewGroup,false);
        ContestListViewHolder holder=new ContestListViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {

        ContestListViewHolder contestListViewHolder= (ContestListViewHolder) viewHolder;
        ConInfo contest=contestLists.get(position);
        final String address= Const.PIC_URL+contest.getThumb();
        String name=contest.getName();
        final String Contest_ID=contest.getId();
        final String Contest_Name=contest.getName();

        contestListViewHolder.contest_name.setText(name);
       // Picasso.with(context).load(address).into(contestListViewHolder.contest_pic);
        if (!contest.getThumb().equals("")){
         Picasso.with(context).load(address).into(contestListViewHolder.contest_pic);
        }else {
            Picasso.with(context).load(R.drawable.top_1).into(contestListViewHolder.contest_pic);
        }

        //////////////////////////点击事件
      /*  contestListViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //启动新的Activity-俱乐部详情
                Intent intent = new Intent(context, ClubInfoActivity.class);
                intent.putExtra("Contest_Id",Contest_ID);
                intent.putExtra("Contest_Name",Contest_Name);
                context.startActivity(intent);//启动Activity的时候要注意，加context
            }
        });
*/
    }

    @Override
    public int getItemCount() {
        return contestLists.size();
    }}